#include<bits/stdc++.h>
using namespace std;
int T;
int a[10001],b[10001],c[10001];
int main(){
	int n,m,l,V;
	cin>>T;
	int d,v1,a1;
	int minn=1;
	int kk1=0;
	for(int i=1;i<=T;i++){
		cin>>n>>m>>l>>V;
		for(int j=1;j<=n;j++){
			cin>>d>>v1>>a1;
			a[i]=v1;
			c[i]=d;
			if(a[i]>V){
				kk1++;
				if(c[i]>=minn)
				  minn=c[i];
			}
			 
		}
	}
	int kk=0;
	for(int i=1;i<=m;i++){
		cin>>b[i];
		if(b[i]<=minn){
			kk++;
		}
	}
	int ans=m-kk;
	if(kk==m){
		ans=0;
		
	}
	else{
		cout<<kk1<<" "<<ans;
	}
	return 0;
}
